package com.guan.service;

import com.guan.core.annotation.Autowired;
import com.guan.core.annotation.Bean;
import com.guan.core.entity.Page;
import com.guan.core.entity.PageData;
import com.guan.jdbc.JDBCBaseDao;

import java.util.ArrayList;
import java.util.List;

/**
 * 商品服务类
 * Created by Administrator on 2018/1/25 0025.
 */
@Bean("productService")
public class ProductService {
    @Autowired("jdbcBaseDao")
    private JDBCBaseDao jdbcBaseDao;

    public Page<PageData> queryProductType(Page<PageData> page){
        PageData p = page.getPd();
        String sql = "SELECT p.product_id,type_id,p.product_name,p.product_storage,p.product_price,p.product_dealamount,p.product_outline,p.product_storetime,p.product_pic FROM t_product_info p";
        List<Object> params =new ArrayList<Object>();
        String condition=" where del_flag=0 ";
        if(p.hasKey("PRODUCT_NAME")){
            condition+=" and product_name like ?";
            params.add("%"+p.get("PRODUCT_NAME")+"%");
        }
        //查询条件里面 时间一个范围
        if(p.hasKey("STARTTIME")){
            condition+=" and product_storetime >= ?";
            params.add(p.get("STARTTIME"));
        }
        if(p.hasKey("ENDTIME")){
            condition+=" and product_storetime < ?";
            params.add(p.get("ENDTIME"));
        }
        int total = jdbcBaseDao.getTotal("select count(1) from t_product_info"+condition, params);
        page.setTotal(total);
        List<PageData> re = jdbcBaseDao.queryPage(sql+condition,params);
        page.setResult(re);
        return  page;
    }
}
